from miller_rabin import factorslist
from permutations import splits

def partitions(list):
    """Generates all possible ways to divide a list in sublists."""
    if 1 >= len(list):
        yield [list]
    else:
        head = list[0]
        tail = list[1:]
        for partitioning in partitions(tail):
            #print [[head]],"+",partitioning,"=",[[head]] + partitioning
            yield [[head]] + partitioning
            for n in xrange(len(partitioning)):
                yield [partitioning[:n]] + [[head] + partitioning[n]] + [partitioning[n + 1:]]


for p in partitions([1, 2, 3]):
    print p
    
exit()                

def products(n):
    f = factorslist(n)
    for (l, r) in splits(f):
        lprod = mul(l)
        
n = 210
f = factorslist(n)
for (l,r) in splits(f):
    print l, r 
